#include "sal.h"

#ifndef _SAL_FIFO_H
#define _SAL_FIFO_H

#define SAL_MIN(x,y) (((x) > (y)) ? (y) : (x))

#define SAL_MAX(x,y) (((x) > (y)) ? (x) : (y))

typedef struct sal_fifo_s
{
    uint8 *buffer;    /* the buffer holding the data */
    uint32 size;              /* the size of the allocated buffer, size is pow of 2 */
    uint32 mask;              /* is equal to size - 1 */
    uint32 in;                /* data is added at offset (in % size) */
    uint32 out;               /* data is extracted from off. (out % size) */
    uint32 prev_in;                /* record prev_in during sal_fifo_get process */
    uint32 prev_out;               /* record prev_out during sal_fifo_put process */   
}sal_fifo_t;



sal_fifo_t* sal_fifo_create(uint32 size);
void sal_fifo_destroy(sal_fifo_t* fifo);
uint32 sal_fifo_put(sal_fifo_t* fifo, uint8 *buffer, uint32 len);
uint32 sal_fifo_get(sal_fifo_t* fifo, uint8 *buffer, uint32 len);
void* sal_fifo_get_buffer(sal_fifo_t *fifo);
uint32 sal_fifo_len(sal_fifo_t *fifo);

#endif
